package io.github.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.github.dao.SysCalllogsDao;
import io.github.entity.SysCallogsEntity;
import io.github.service.SysCalllogsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author: weil
 * @date: 2019/9/18 20:33
 * @version: 1.0
 * @description:
 */
@Service
public class SysCalllogsServiceImpl extends ServiceImpl<SysCalllogsDao, SysCallogsEntity> implements SysCalllogsService {


    @Resource
    SysCalllogsDao calllogsDao;


    /**
     *
     * @param offset
     * @param limit
     * @param startTime 起始时间
     * @param endTime  结束时间
     * @param caller  主叫
     * @param order
     * @param callee  被叫
     * @param callerBelong  主叫归属  分管单位名称
     * @param calleeBelong  被叫归属  工会名称
     * @param calleeTransfer
     * @return
     */
    @Override
    public Page<SysCallogsEntity> queryListByPage2(Integer offset, Integer limit,String startTime,String endTime,String caller,
                                                  Boolean order,String callee,String callerBelong,String calleeBelong,String calleeTransfer) {


        Page<SysCallogsEntity> page = new Page<>(offset, limit);

        List list = calllogsDao.queryList2(page,caller,callee,startTime,endTime);

        page.setRecords(list);
        return page;
    }

    @Override
    public Page<SysCallogsEntity> queryListByPage(Integer offset, Integer limit, String sort,String startTime,String endTime,String caller,
                                                  Boolean order,String callee) {
        Wrapper<SysCallogsEntity> wrapper = new EntityWrapper<SysCallogsEntity>();

        if(StringUtils.isNoneBlank(caller)){
            wrapper.like("caller",caller);
        }
        if(StringUtils.isNoneBlank(startTime,endTime)){
            wrapper.between("caller_start_time",startTime,endTime);
        }
        if(StringUtils.isNotBlank(callee)){
            wrapper.like("callee",callee);
        }
        wrapper.orderBy("id",false);
        Page<SysCallogsEntity> page = new Page<>(offset,limit);
        return this.selectPage(page,wrapper);

    }


    @Override
    public List<SysCallogsEntity> queryAllLogs() {

        return baseMapper.queryAllLogs();
    }

    @Override
    public SysCallogsEntity queryByAreaid(Integer areaid) {
        return baseMapper.queryByAreaid(areaid);
    }

    @Override
    public Long getNumber(String tempTime){
        return baseMapper.getNumber(tempTime);
    }



    @Override
    public List statistics(JSONObject json) {

        return null;
    }

}
